package com.weijianhuawen.wjblog.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-15 0:39
 */

@Slf4j
public class JsonUtil {
    private static final ObjectMapper INSTANCE =  new ObjectMapper();

    // 将对象转换为json字符串
    public static String toJsonString(Object obj) {
        try {
            return INSTANCE.writeValueAsString(obj);
        } catch (JsonProcessingException exception) {
            return obj.toString();
        }
    }
}
